#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long ll;
const int N = 4e2 + 5;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int n, a[N], b[N], h[N], atk;
ll f[N][N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("cat.in", "r", stdin);
  freopen("cat.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &atk);
  for (int i = 1; i <= n; ++i) { scanf("%d%d%d", &a[i], &b[i], &h[i]); }
  for (int i = 1; i <= n; ++i) {
    for (int l = 1; l <= n - i + 1; ++l) {
      int r = l + i - 1;
      f[l][r] = inf;
      for (int k = l; k <= r; ++k) {
        f[l][r] = std::min(f[l][r], f[l][k - 1] + f[k + 1][r] +
                                        1ll * ((h[k] + atk - 1) / atk) *
                                            (a[k] + b[l - 1] + b[r + 1]));
      }
    }
  }
  printf("%lld", f[1][n]);
  return 0;
}